🛡️ Sentinel: [CRITICAL] Fix Auth Bypass - Enforce Invite Code Validation - #411
🛡️ Sentinel: [CRITICAL] Fix Auth Bypass - Enforce Invite Code Validation#411criptogus wants to merge 1 commit into
Conversation
- Modified `POST /api/auth/register` to require `inviteCode`. - Added validation logic against `invitation_codes` table (existence, expiry, max uses). - Wrapped user creation and invite usage increment in a database transaction for data integrity. - Added regression test `backend/src/tests/routes/auth-invite.test.ts` to verify the fix and prevent regression. This fixes a critical vulnerability where the registration endpoint allowed bypassing the invite-only restriction. Co-authored-by: criptogus <128640021+criptogus@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 31c445a1ee
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Increment invitation usage | ||
| await client.query('UPDATE invitation_codes SET current_uses = current_uses + 1 WHERE id = $1', [invitation.id]); |
There was a problem hiding this comment.
Enforce invite usage limit atomically
The invite limit is validated before the transaction and the update here is unconditional, so two concurrent registrations can both pass the pre-check and then increment current_uses, allowing more users than max_uses. This shows up when an invite has only one remaining use (or is at its limit) and two requests arrive close together. Consider moving the invite lookup into the same transaction with SELECT ... FOR UPDATE, or make this UPDATE conditional on current_uses < max_uses and check the affected row count before completing registration.
Useful? React with 👍 / 👎.
Vulnerability Fixed:
The
POST /api/auth/registerendpoint accepted aninviteCodebut did not validate it, allowing any user to register even if the system was intended to be Invite-Only (as suggested by the frontend "Waiting List" redirection).Resolution:
inviteCodeagainst theinvitation_codestable.backend/src/tests/routes/auth-invite.test.tsverifying:Learnings Recorded:
Updated
.Jules/sentinel.mdwith findings regarding backend enforcement vs frontend obscurity.PR created automatically by Jules for task 6239222094704057239 started by @criptogus